<?php
/*
 * Last Edited: 27-7-2013
 */
class TransactionModel extends Zend_Db_Table_Abstract{
	protected $_name = 'transaction_history';
	protected $_primary = 'id';
    protected $_itemPerPage = 5;
	
    public function getList($params = NULL){

		$db = Zend_Registry::get('connectDB');
        $mysql = $db->select()
					->from($this->_name);
        if(!empty($params['user_name'])){
            $mysql->where("user_receive_name = ?", $params['user_name']);
        }
        if(!empty($params['game_id'])){
            $mysql->where("game_id = ?", $params['game_id']);
        }
        $mysql->where("status = 1");
        $list = $db->fetchAll($mysql);
        return $list;
	}

    public function multiDelete($params,$options=NULL){
		if (!empty($params))	
			foreach ($params as $key => $id) {
				$where = array("id = ".intval($id));
				if ($id != 0) {
					self::delete($where);	
				}
			}
    }
    
    public function getItem($params=NULL,$options=NULL){
		if (isset($params['id'])){			
			$db = Zend_Registry::get('connectDB');
			$mySql = $db->select()
						->from($this->_name)
						->where('id = ?', $params['id']);
			return $db->fetchRow($mySql);	
		}
		return false;
	}
    
    public function getTransaction($params=NULL,$options=NULL){
		if (isset($params['transaction_id'])){			
			$db = Zend_Registry::get('connectDB');
			$mySql = $db->select()
						->from($this->_name)
						->where('transaction_id = ?', $params['transaction_id'])
                        ->where("status = 1");
			return $db->fetchRow($mySql);	
		}
		return false;
	}
    
    public function updateAppota($params){
        $db = Zend_Registry::get('connectDB');
		$db->insert("appota_tran", $params);	
    }
}